package br.ucb.sigplan.action.impl;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ucb.sigplan.action.Action;
import br.ucb.sigplan.validator.Validator;

public class EscolheTurmaAction implements Action{

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<String> erros = Validator.validaTurmaEscolhida(req);
		if (!erros.isEmpty()) {
			req.setAttribute("erros", erros);
			return "/jsp/professor/plano/profEscolheTurma.jsp";
		}
		req.getSession().removeAttribute("turmas");
		if (req.getParameter("acao").equalsIgnoreCase("cadastrar")) {
			return "abrirCadastraConteudoTurma.do?idTurma="+req.getParameter("turmaSelecao");
		}else {
			return "abrirAlteraConteudoTurma.do?idTurma="+req.getParameter("turmaSelecao");
		}
	}

}
